namespace _ReplaceString_.UI;

public abstract record UIAnimation
{
	public void Play(UIBase ui)
	{
		int timer = -1;
		var _coroutine = Update(ui).GetEnumerator();
		void UpdateCoroutine(UIElement affectedElement)
		{
			if (timer < 0)
			{
				Begin(ui);
				timer = 0;
			}
			else if (timer > 0)
			{
				timer--;
				return;
			}

			if (_coroutine.MoveNext())
			{
				timer = _coroutine.Current;
			}
			else
			{
				affectedElement.OnUpdate -= UpdateCoroutine;
			}
		}
		ui.OnUpdate += UpdateCoroutine;
	}
	public virtual void Begin(UIBase ui) { }

	public abstract IEnumerable<int> Update(UIBase ui);
}